# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
# This source file is part of the Cangjie project, licensed under Apache-2.0
# with Runtime Library Exception.
#
# See https://cangjie-lang.cn/pages/LICENSE for license information.

from os import path

integer_types = ['Int8', 'Int16', 'Int32', 'Int64', 'IntNative', 'UInt8', 'UInt16', 'UInt32', 'UInt64', 'UIntNative']
number_types = integer_types + ['Float16', 'Float32', 'Float64']
other_types = ['String', 'Rune', 'Bool', 'Unit', 'Tuple', 'Array', 'Range', 'C', 'S']
types = number_types + other_types

custom_type_template = '''
%s {
    let x : Int64

    init(y : Int64) { x = y }

    operator func ==(other : %s) { x == other.x }
}
'''
decl_map = {'Array': '\ntype Array = Array<Int64>\n', 'Tuple': '\ntype Tuple = (Int64, Int64)\n',
            'Range': '\ntype Range = Range<Int64>\n', 'Function': '\ntype Function = (Int64) -> Int64\n',
            'C': custom_type_template % ('class C', 'C'), 'S': custom_type_template % ('struct S', 'S')}
def decl(ty : str) -> str:
  if ty in decl_map: return decl_map[ty]
  return ''

dir = path.dirname(path.realpath(__file__))
path = dir + '/test_' + path.basename(dir) + '_{}.cj'
template = '''
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 * This source file is part of the Cangjie project, licensed under Apache-2.0
 * with Runtime Library Exception.
 *
 * See https://cangjie-lang.cn/pages/LICENSE for license information.
 */

/*
  @Assertion:   4.7.3(9) Thus the return type in the containing function must be Unit otherwise, an error is reported.
  @Description: %s
  @Mode: %s
  @Negative: %s
  @Structure: single
  @CompileWarning: ignore
  @Comment: Auto-generated by gen.py
*/
{}
func f() : {t} {{ return }}

main() {{
    f()
    0
}}
'''
negative_template = template % ('Checks that function with return type {t} cannot contain return without expression.',
                                'compileonly', 'yes')
positive_test =  template.format('', t='Unit') %\
('Checks that value of type T can be returned from a function with return type T for various T,', 'run', 'no')
counter = 1

def write_counted(contents : str):
  global counter
  with open(path.format(str(counter).zfill(2)), 'w') as file:
    file.write(contents)
    counter += 1

write_counted(positive_test)
for test in [negative_template.format(decl(t), t=t) for t in types if t != 'Unit']:
  write_counted(test)
